package com.txunda.zhuohired.adapter.user.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;

import java.util.List;


/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/2/27 9:18
 * 功能描述：全部职位adapter
 * 联系方式：jiahuanchen@126.com
 */

public class PartTimeStatusAdapter extends BaseAdapter {

    private Context context;
    private ViewHolder holder;
    private List<String> statusList;
    private int status;
    /**
     * 自定义监听
     */
    private HolderClickListener mHolderClickListener;

    public PartTimeStatusAdapter(Context context, List<String> statusList, int status) {
        this.context = context;
        this.statusList = statusList;
        this.status = status;
    }

    @Override
    public int getCount() {
        return statusList.size();
    }

    @Override
    public Object getItem(int i) {
        return statusList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_part_time_status, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (i == status) {
            holder.tv_item_part_time_status.setBackgroundResource(R.drawable.shape_common_bottom);
            holder.tv_item_part_time_status.setTextColor(context.getResources().getColor(R.color.white));
        } else {
            holder.tv_item_part_time_status.setBackgroundResource(R.drawable.shape_home_png);
            holder.tv_item_part_time_status.setTextColor(context.getResources().getColor(R.color.home_grey3));
        }
        holder.tv_item_part_time_status.setText(statusList.get(i));
        holder.tv_item_part_time_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                status = i;
                notifyDataSetChanged();
                mHolderClickListener.onHolderClick(i);
            }
        });
        return view;
    }

    class ViewHolder {
        @ViewInject(R.id.tv_item_part_time_status)
        private TextView tv_item_part_time_status;
    }
    /**
     * 自定义监听
     *
     * @param holderClickListener
     */
    public void SetClickListener(HolderClickListener holderClickListener) {
        this.mHolderClickListener = holderClickListener;
    }

    /**
     * 自定义监听
     *
     * @
     */
    public interface HolderClickListener {
        void onHolderClick(int position);
    }
}
